<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="样品名称" prop="ypmc">
        <el-input
          v-model="queryParams.ypmc"
          placeholder="请输入样品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品编号" prop="cpbh">
        <el-input
          v-model="queryParams.cpbh"
          placeholder="请输入产品编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="气味分析" prop="qwfx">
        <el-input
          v-model="queryParams.qwfx"
          placeholder="请输入气味分析"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="滋味分析" prop="zwfx">
        <el-input
          v-model="queryParams.zwfx"
          placeholder="请输入滋味分析"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="zt">
        <el-input
          v-model="queryParams.zt"
          placeholder="请输入状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="色度" prop="sd">
        <el-input
          v-model="queryParams.sd"
          placeholder="请输入色度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="浊度" prop="zd">
        <el-input
          v-model="queryParams.zd"
          placeholder="请输入浊度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="净含量≤2L 体积法" prop="jhlx2">
        <el-input
          v-model="queryParams.jhlx2"
          placeholder="请输入净含量≤2L 体积法"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="净含量>2L 称量法" prop="jhld2">
        <el-input
          v-model="queryParams.jhld2"
          placeholder="请输入净含量>2L 称量法"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电导率" prop="ddl">
        <el-input
          v-model="queryParams.ddl"
          placeholder="请输入电导率"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="溴酸盐" prop="xsy">
        <el-input
          v-model="queryParams.xsy"
          placeholder="请输入溴酸盐"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报表编号" prop="bbbh">
        <el-input
          v-model="queryParams.bbbh"
          placeholder="请输入报表编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['Laboratory_sensory_sub:sensory_sub:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['Laboratory_sensory_sub:sensory_sub:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['Laboratory_sensory_sub:sensory_sub:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['Laboratory_sensory_sub:sensory_sub:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="sensory_subList"
      @selection-change="handleSelectionChange"
      max-height="550"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="报表编号" align="center" prop="id" />
      <el-table-column label="样品名称" align="center" prop="ypmc" />
      <el-table-column label="产品编号" align="center" prop="cpbh" />
      <el-table-column label="气味分析" align="center" prop="qwfx" />
      <el-table-column label="滋味分析" align="center" prop="zwfx" />
      <el-table-column label="状态" align="center" prop="zt" />
      <el-table-column label="色度" align="center" prop="sd" />
      <el-table-column label="浊度" align="center" prop="zd" />
      <el-table-column label="净含量≤2L 体积法" align="center" prop="jhlx2" />
      <el-table-column label="净含量>2L 称量法" align="center" prop="jhld2" />
      <el-table-column label="电导率" align="center" prop="ddl" />
      <el-table-column label="溴酸盐" align="center" prop="xsy" />
      <el-table-column label="报表编号" align="center" prop="bbbh" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="主表主键" align="center" prop="parentid" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="180px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['Laboratory_sensory_sub:sensory_sub:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['Laboratory_sensory_sub:sensory_sub:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改感官检验子对话框 -->
    <el-dialog
      v-myFullscreen
      :title="title"
      :visible.sync="open"
      width="900px"
      append-to-body
      fullscreen
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="样品名称" prop="ypmc">
              <el-input
                v-model="form.ypmc"
                placeholder="请输入样品名称"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品编号" prop="cpbh">
              <el-input
                v-model="form.cpbh"
                placeholder="请输入产品编号"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="气味分析" prop="qwfx">
              <el-input
                v-model="form.qwfx"
                placeholder="请输入气味分析"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="滋味分析" prop="zwfx">
              <el-input
                v-model="form.zwfx"
                placeholder="请输入滋味分析"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="zt">
              <el-input
                v-model="form.zt"
                placeholder="请输入状态"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="色度" prop="sd">
              <el-input
                v-model="form.sd"
                placeholder="请输入色度"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="浊度" prop="zd">
              <el-input
                v-model="form.zd"
                placeholder="请输入浊度"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="净含量≤2L 体积法" prop="jhlx2">
              <el-input
                v-model="form.jhlx2"
                placeholder="请输入净含量≤2L 体积法"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="净含量>2L 称量法" prop="jhld2">
              <el-input
                v-model="form.jhld2"
                placeholder="请输入净含量>2L 称量法"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电导率" prop="ddl">
              <el-input
                v-model="form.ddl"
                placeholder="请输入电导率"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="溴酸盐" prop="xsy">
              <el-input
                v-model="form.xsy"
                placeholder="请输入溴酸盐"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报表编号" prop="bbbh">
              <el-input
                v-model="form.bbbh"
                placeholder="请输入报表编号"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入备注"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="主表主键" prop="parentid">
              <el-input
                v-model="form.parentid"
                placeholder="请输入主表主键"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSensory_sub,
  getSensory_sub,
  delSensory_sub,
  addSensory_sub,
  updateSensory_sub,
} from "@/api/quality/productionline/sensory_sub";

export default {
  name: "Sensory_sub",
  data() {
    return {
      //弹窗是否禁止编辑
      openDisabled: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 感官检验子表格数据
      sensory_subList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        ypmc: null,
        cpbh: null,
        qwfx: null,
        zwfx: null,
        zt: null,
        sd: null,
        zd: null,
        jhlx2: null,
        jhld2: null,
        ddl: null,
        xsy: null,
        bbbh: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询感官检验子列表 */
    getList() {
      this.loading = true;
      listSensory_sub(this.queryParams).then((response) => {
        this.sensory_subList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        ypmc: null,
        cpbh: null,
        qwfx: null,
        zwfx: null,
        zt: null,
        sd: null,
        zd: null,
        jhlx2: null,
        jhld2: null,
        ddl: null,
        xsy: null,
        bbbh: null,
        remark: null,
        parentid: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openDisabled = false;
      this.open = true;
      this.title = "添加感官检验子";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.openDisabled = false;
      const id = row.id || this.ids;
      getSensory_sub(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改感官检验子";
      });
    },
    /** 查看按钮 */
    handleView(row) {
      this.reset();
      this.openDisabled = true;
      const id = row.id || this.ids;
      getSensory_sub(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "查看感官检验子";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {

        if (valid) {
            /**打开遮罩层*/
            const rLoading = this.openLoading();
          if (this.form.id != null) {
            updateSensory_sub(this.form)
              .then((response) => {
                /**成功后执行关闭遮罩层*/
                rLoading.close();
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .catch((error) => {
                /**请求异常后执行关闭遮罩层*/
                rLoading.close();
              });
          } else {
            addSensory_sub(this.form)
              .then((response) => {
                /**成功后执行关闭遮罩层*/
                rLoading.close();
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .catch((error) => {
                /**请求异常后执行关闭遮罩层*/
                rLoading.close();
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除感官检验子编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delSensory_sub(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "Laboratory_sensory_sub/sensory_sub/export",
        {
          ...this.queryParams,
        },
        `Laboratory_sensory_sub_sensory_sub.xlsx`
      );
    },
  },
};
</script>
